package com.itheima.controller;


import com.itheima.anno.Log;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;


    @GetMapping
    public Result Page(StudentQueryParam stu){

        PageBean pageBean = studentService.page(stu);

        return Result.success(pageBean);

    }

    @Log
    @PostMapping
    public Result add(@RequestBody Student student){
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    @Log
    @PutMapping
    public Result modify(@RequestBody Student s){
        studentService.modify(s);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List ids){
        studentService.delete(ids);
        return Result.success();
    }

    @Log
    @PutMapping("/violation/{id}/{score}")
    public Result violate(@PathVariable Integer id,
                          @PathVariable Integer score){

        studentService.violate(id,score);
        return Result.success();
    }
}
